﻿using System.Web.UI.WebControls;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.Collectors;
namespace Ue.Qcdz.UI.Controls
{
    /// <summary>
    /// 采集站点编辑控件
    /// </summary>
    public class CollectorEdit : SkinnedEntityEdit<Collector>
    {
        private TextBox tbxSiteName;
        private TextBox tbxSiteUrl;
        private TextBox tbxOutskirts;//栏目定位
        private TextBox tbxALink;
        private TextBox tbxEncode;
        //
        private TextBox tbxNewsOutskirts;//文章定位
        private TextBox tbxTitle;
        private TextBox tbxEditor;
        private TextBox tbxReference;
        private TextBox tbxImageUrl;
        private TextBox tbxContent;

        private RadioButtonList rBtnListstatus;

        private HiddenField hdfCollectKey;

        public CollectorEdit()
        {
            this.ReturnUrl = Domain.SiteUrls.Instance.CollectorManage();
        }

        protected override Collector Enttiy
        {
            get
            {
                Collector model = Domain.Collectors.CollectorService.GetCollector(this.EntityKey);
                if (model == null)
                    model = new Collector(this.EntityKey);
                if (tbxSiteName != null)
                    model.SiteName = tbxSiteName.GetValue<string>();
                if (tbxSiteUrl != null)
                    model.SiteUrl = tbxSiteUrl.GetValue<string>();
                if (tbxOutskirts != null)
                    model.Outskirts = tbxOutskirts.GetValue<string>();
                if (tbxReference != null)
                    model.Reference = tbxReference.GetValue<string>();
                if (tbxALink != null)
                    model.ALink = tbxALink.GetValue<string>();
                if (tbxEncode != null)
                    model.Encode = tbxEncode.GetValue<string>();
                //
                if (tbxNewsOutskirts != null)
                    model.NewsOutskirts = tbxNewsOutskirts.GetValue<string>();
                if (tbxTitle != null)
                    model.Title = tbxTitle.GetValue<string>();
                if (tbxImageUrl != null)
                    model.ImageUrl = tbxImageUrl.GetValue<string>();
                if (tbxEditor != null)
                    model.Editor = tbxEditor.GetValue<string>();
                if (tbxReference != null)
                    model.Reference = tbxReference.GetValue<string>();
                if (tbxContent != null)
                    model.Content = tbxContent.GetValue<string>();
                if (rBtnListstatus != null)
                    model.Status = rBtnListstatus.SelectedValue == "1" ? 1 : 0;


                return model;
            }
            set
            {
                if (value == null)
                    return;
                tbxSiteName.SetValue(value.SiteName);
                tbxSiteUrl.SetValue(value.SiteUrl);
                tbxOutskirts.SetValue(value.Outskirts);
                tbxReference.SetValue(value.Reference);
                tbxALink.SetValue(value.ALink);
                tbxEncode.SetValue(value.Encode);
                //
                tbxNewsOutskirts.SetValue(value.NewsOutskirts);
                tbxTitle.SetValue(value.Title);
                tbxEditor.SetValue(value.Editor);
                tbxReference.SetValue(value.Reference);
                tbxImageUrl.SetValue(value.ImageUrl);
                tbxContent.SetValue(value.Content);
                rBtnListstatus.SelectedIndex = -1;
                rBtnListstatus.Items.FindByValue(value.Status.ToString()).Selected = true;
                //
                if (hdfCollectKey != null)
                    hdfCollectKey.Value = value.Key.ToString();
            }
        }

        protected override void InitSkin(System.Web.UI.Control skin)
        {
            tbxSiteName = skin.FindControl<TextBox>("tbxSiteName");
            tbxSiteUrl = skin.FindControl<TextBox>("tbxSiteUrl");
            tbxOutskirts = skin.FindControl<TextBox>("tbxOutskirts");
            tbxALink = skin.FindControl<TextBox>("tbxALink");
            tbxEncode = skin.FindControl<TextBox>("tbxEncode");
            //
            tbxNewsOutskirts = skin.FindControl<TextBox>("tbxNewsOutskirts");
            tbxTitle = skin.FindControl<TextBox>("tbxTitle");
            tbxEditor = skin.FindControl<TextBox>("tbxEditor");
            tbxReference = skin.FindControl<TextBox>("tbxReference");
            tbxImageUrl = skin.FindControl<TextBox>("tbxImageUrl");
            tbxContent = skin.FindControl<TextBox>("tbxContent");
            //
            rBtnListstatus = skin.FindControl<RadioButtonList>("rBtnListstatus");
            //
            hdfCollectKey = skin.FindControl<HiddenField>("hdfCollectKey");


        }

        protected override string GetSkinFileName()
        {
            return "~/Admin/Themes/Skins/Collectors/CollectorEdit.ascx";
        }
    }
}
